package com.zzh.net.Interceptor;


import com.zzh.tools.log.ToolLog;
import com.zzh.tools.sp.ToolSpUtils;

import java.io.IOException;
import java.util.HashSet;
import java.util.logging.Logger;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * copy by 孟家敏 on 16/12/8 15:51
 * <p>
 * 邮箱：androidformjm@sina.com
 * Created by Tamic on 2016-12-08.
 */
public class AddCookiesInterceptor implements Interceptor {

    public AddCookiesInterceptor() {
        super();
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        HashSet<String> preferences = (HashSet<String>) ToolSpUtils.getStringSet("cookie");
        if (preferences != null) {
            for (String cookie : preferences) {
                builder.addHeader("Cookie", cookie);
                ToolLog.d("Cookie:  " + cookie);
            }
        }
        return chain.proceed(builder.build());

    }
}